package com.lxlg.lxlg_order.app.controller;

import com.lxlg.core.utils.Result;
import com.lxlg.lxlg_order.client.FormGoodOrderClient;
import com.lxlg.lxlg_order.client.param.*;
import com.lxlg.lxlg_order.service.service.GoodsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kevin
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/infra/goods-order")
@Api("普通订单操作，物流操作，订单状态操作")
public class GoodsOrderController implements FormGoodOrderClient {
    @Resource
    private GoodsOrderService goodsOrderService;

    @Override
    @PostMapping("newFormOrder")
    public Result<String> newFormOrder(@Valid @RequestBody FormOrderForm formOrderForm ) {
        return goodsOrderService.addFormOrder(formOrderForm);
    }

    @Override
    @PostMapping("payFormOrder")
    public void payFormOrder(@Valid @RequestBody FormOrderPayFOrm formOrderPayFOrm, HttpServletResponse resp) throws IOException {
         goodsOrderService.payFormOrder(formOrderPayFOrm,resp);
    }

    @Override
    @PostMapping("cancleFormOrder")
    @ApiOperation("取消订单")

    public Result<String> cancleFormOrder(@Valid @RequestBody CancleFormOrderForm cancleFormOrderForm) {
        return goodsOrderService.cancleFormOrder(cancleFormOrderForm.getFormOrderCode());
    }

    @Override
    @ApiOperation("商品发货")
    @PostMapping("delivergoods")
    public Result<String> deliverGoods(@Valid @RequestBody DeliverGoodsForm deliverGoodsForm) {
        return goodsOrderService.doDeliverGoods(deliverGoodsForm);
    }

    @Override
    @PostMapping("changedeliverGoodsState")
    @ApiOperation("修改物流状态")
    public Result<String> changedeliverGoodsStateBycompany(@Valid @RequestBody LogisticsStateForm logisticsStateForm) {
        return goodsOrderService.doChangedeliverGoodsState(logisticsStateForm);
    }



}

